package org.example.design.decorator.itf.impl;

import org.example.design.decorator.itf.HandlerInterceptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Classname LoginSsoDecorator02
 * @Description 装饰模式具体实现
 * @Date 2020/11/5 10:10 上午
 * @Created by xiangjd
 */
public class LoginSsoDecorator02 extends SsoDecorator {
    private Logger logger = LoggerFactory.getLogger(LoginSsoDecorator02.class);
    private static Map<String, String> authMap = new ConcurrentHashMap<String, String>();

    static {
        authMap.put("huahua", "queryUserInfo");
        authMap.put("doudou", "queryUserInfo");
    }

    public LoginSsoDecorator02(HandlerInterceptor handlerInterceptor) {
        super(handlerInterceptor);
    }

    @Override
    public boolean prehandle(String requset, String response, Object handle) {
        boolean success = super.prehandle(requset, response, handle);
        if (!success) {
            return false;
        }
        String userId = requset.substring(8);
        String method = authMap.get(userId);
        logger.info("模拟单点登录拦截方法，requset:{},method:{}", requset, method);
        return "queryUserInfo".equals(method);
    }
}
